﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Alogient.Cameleon.Sdk.Items
{
    [Serializable]
    public class CMElementCollection : List<CMElement>
    {
        #region Accessors
        
        public CMElement this[string elementName]
        {
            get
            {
                if (this.Count == 0)
                {
                    throw new CMException(String.Format("Attempt to get '{0}' in empty CMElementCollection", elementName));
                }

                foreach (CMElement element in this)
                {
                    if (element.ElementName == elementName)
                    {
                        return element;
                    }
                }

                throw new CMException(String.Format("Key '{0}' not found in CMElementCollection", elementName));
            }
        }

        #endregion

        public bool Exists(string elementName)
        {
            return this.Contains(elementName);
        }

        public bool Contains(string value)
        {
            return this.Any(element => element.ElementName == value);
        }
    }
}
